﻿<!--#include virtual="/Common/Config.asp" -->
<!--#include virtual="/Common/conn.asp" -->
<!--#include virtual="/2010admin/Check_IsLogin.asp" -->
<!--#include virtual="/Common/Function.asp" -->

<%
If Request.ServerVariables ("Request_Method")="POST" Then

	action = requery("action")

	Select Case action
			Case "add"  Call Add()	
			Case "edit" Call Edit()	
			Case "del"  Call Del()
	End Select
Else
	BT_ID = requery("BT_ID")
	Call Check_Isnumeric_Msg(BT_ID,"一级分类ID")

End If

Function Add()

	sIT_Name = reform("sIT_Name")

	BT_ID	  = reform("BT_ID")
	Call Check_Isnumeric_Msg(BT_ID,"一级分类ID")

	Call Check_Length(sIT_Name,5000,1,"二级分类名称")
	IT_Name_Array = Split(sIT_Name,",")

	'检查数据
	For i=0 To UBound(IT_Name_Array)
		Call Check_Length(IT_Name_Array(i),10,1,"二级分类名称")
	Next 
	
	Max_Order = Get_FirstValue("SELECT ISNULL(Max(IT_Order),0) FROM News_Small_Type ")


	'加入数据
	For i=0 To UBound(IT_Name_Array)

		Sql = "INSERT INTO News_Small_Type(BT_ID,IT_Name,IT_Order) VALUES("&_
			  ""&BT_ID&_
			  ",'"&IT_Name_Array(i)&"'"&_
			  ","&(Max_Order+i+1)&_	
			  ")"

		conn.execute(sql)

	Next 



	
	AlertBox "增加成功!","Info_SmallType_Query.asp?BT_ID="&BT_ID	

End Function 


Function Edit()

	IT_ID_Str = reform("IT_ID")
	If IT_ID_Str="" Then
		AlertBox "请选择要修改的记录!","javascript:history.go(-1)"	
	End If
	

	BT_ID	  = reform("BT_ID")
	Call Check_Isnumeric_Msg(BT_ID,"一级分类ID")

	'ENDD
	IT_ID_Array = Split(IT_ID_Str,",")
	For i=0 To UBound(IT_ID_Array)

		iIT_ID = Trim(CStr(IT_ID_Array(i)))

		sIT_Name = reform("IT_Name"&iIT_ID)

		iIT_Order= reform("IT_Order"&iIT_ID)
		
		Call Check_Length(sIT_Name,10,1,"分类名称")
		Call Check_IsNumeric(iIT_Order)

	Next

	For i=0 To UBound(IT_ID_Array)

		iIT_ID = Trim(IT_ID_Array(i))
		sIT_Name = reform("IT_Name"&iIT_ID)

		iIT_Order= reform("IT_Order"&iIT_ID)

		Sql = "UPDATE News_Small_Type SET IT_Name='"&sIT_Name&"'"&_
			  ",IT_Order="&iIT_Order&_
			  "WHERE IT_ID="&iIT_ID

		conn.execute(sql)


	Next
	
	AlertBox "修改成功!","Info_SmallType_Query.asp?BT_ID="&BT_ID	

End Function 

Function Del()

	iIT_ID = reform("IT_ID")

	BT_ID	  = reform("BT_ID")
	Call Check_Isnumeric_Msg(BT_ID,"一级分类ID")

	Sql = "DELETE FROM News_Small_Type WHERE IT_ID IN ("&iIT_ID &")"
	conn.execute(sql)

	
	AlertBox "删除成功!","Info_SmallType_Query.asp?BT_ID="&BT_ID	

End Function 


%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="/2010admin/css/default.css" type="text/css" rel="stylesheet">
<title><%=web_title%></title>
<script language="javascript" src="/2010admin/js/validator.js"></script>

<script language="javascript"> 
function checkall(field)
{
if(document.form.list2.checked==true){
for(i=0;i<field.length;i++){
field[i].checked=true;}
document.form.list2.checked==true
}
else {
for(i=0;i<field.length;i++){
field[i].checked=false;}
document.form.list2.checked==false
}
}
function checkform()
{
 var groups = document.getElementsByName("IT_ID");
 var hasChecked = 0;
 for(var i=0; i<groups.length;i++)
	if(groups[i].checked) hasChecked++;
	
if(hasChecked==0)
{
	alert("至少选择一条要修改的记录!");
	return false;
}
else document.form.submit();
}
</script> 
<script language="javascript">
<!--
	function delcheck(){
	 var groups = document.getElementsByName("IT_ID");
	 var hasChecked = 0;
	 for(var i=0; i<groups.length;i++)
		if(groups[i].checked) hasChecked++;
		
	if(hasChecked==0)
	{
		alert("至少选择一条要删除的记录!");
		return false;
	}

	if (confirm('是否真的要删除这条记录？')) {
		document.form.action="Info_SmallType_Query.asp?action=del";
		document.form.submit();
	}
	else return false;
}
//-->
</script>
</head>
<body >
<table border="0" width="100%" cellSpacing="0" cellPadding="0">
  <tr>
    <td width="100%" height="5"></td>
  </tr>
  <tr>
    <td width="100%" align="center">
      <table border="0" width="98%" cellSpacing="0" cellPadding="0">
        <tr>
          <td width="*" align="center" valign="top">
            <table border="0" width="100%" cellSpacing="0" cellPadding="0" class="lrbtline">
              <tr>
                <td width="100%" height="25" class="tbtop">管理导航</td>
              </tr>
              <tr>
                <td width="100%" align="center">
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                    <tr>
                      <td width="100%" height="5"></td>
                    </tr>
                  </table>
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                    <tr>
                      <td width="100%" height="20">&nbsp;<img src="/2010admin/images/sico.gif" border="0">&nbsp;<span id="userlist"><a href="Info_BigType_Query.asp">一级分类</a></span></td>
                    </tr>
                    <tr>
                      <td width="100%" height="5"></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
            <table border="0" width="100%" cellSpacing="0" cellPadding="0">
              <tr>
                <td width="100%" height="5"></td>
              </tr>
            </table>
			<%
			
			sql="SELECT IT_ID,IT_Name,IT_Order FROM News_Small_Type WHERE BT_ID="&BT_ID&" ORDER BY IT_Order ASC"

			Set rs=conn.execute(sql)

			If Not rs.Eof Then

			%>
            <table border="0" width="100%" cellSpacing="0" cellPadding="0" class="lrbtline">
              <tr>
                <td width="100%" height="25" class="tbtop">修改二级分类</td>
              </tr>
              <tr>
                <td width="100%" align="center">
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                    <tr>
                      <td width="100%" height="5"></td>
                    </tr>
                  </table>
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                  <form action="?action=edit" method="post" name="form" >

                    <tr>
                      <td height="25"><div align="center">选择</div></td>
                      <td>二级分类</td>
                    <td>顺序</td>
                    <td>&nbsp;</td>
                    </tr>
					<%
					Do While Not rs.Eof 
						IT_Name=rs(1)
						IT_Order=rs(2)
						
					%>
                    <tr>
                      <td width="139" height="25"><div align="center">
                        <input name="IT_ID" type="checkbox" id="IT_ID" value="<%=rs(0)%>" >
                      </div></td>
                      <td width="166">
					  <input name="IT_Name<%=rs(0)%>" type="text" id="IT_Name" value="<%=IT_Name%>" size="20" ></td>
                    <td width="157">
					<input name="IT_Order<%=rs(0)%>" type="text" id="IT_Order" value="<%=IT_Order%>" size="20" ></td>
                    <td width="751">&nbsp;</td>
                    </tr>
					<%
					rs.movenext
					Loop
					%>
                    <tr>
                      <td height="25"><div align="center">
 						<input type=checkbox name="list2" onClick="checkall(this.form.IT_ID);"  >

                        </div></td>
                      <td colspan="3"><input type="button" name="button1" value="修改" class="button" onClick="return checkform();">&nbsp;<input type="button" name="button2" value="删除" class="button" onClick="return delcheck();"><input type="hidden" name="BT_ID" value="<%=BT_ID%>" class="button"></td>
                    </tr>
                  </form>
                  </table>
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                    <tr>
                      <td width="100%" height="5"></td>
                    </tr>
                  </table>
			 <%
			 End If 

			 rs.close
			 %>

            <table border="0" width="100%" cellSpacing="0" cellPadding="0" class="lrbtline">
              <tr>
                <td width="100%" height="25" class="tbtop">增加二级分类</td>
              </tr>
              <tr>
                <td width="100%" align="center">
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                    <tr>
                      <td width="100%" height="5"></td>
                    </tr>
                  </table>
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                  <form action="?action=add" method="post" name="form1" onSubmit="return Validator.Validate(this, 2)">

                    <tr>
                      <td width="137" height="25"><div align="center">分类名称</div></td>
                      <td width="1074"><input name="sIT_Name" type="text" id="sIT_Name" value="" size="80" dtype="Limit" min="2" max="5000" dmsg="二级分类必须在2-5000个字符间" ></td>
                    </tr>
                     <tr>
                      <td height="25" colspan="2">
                        可批量加入，分类之间用英文,分隔</td>
                      </tr>
                    <tr>
                      <td height="25" colspan="2">
					  <input type="submit" name="submit" value="修改" class="button">
					  <input type="hidden" name="BT_ID" value="<%=BT_ID%>" class="button">
					  </td>
                      </tr>
                  </form>
                  </table>

                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td width="100%" height="5"></td>
  </tr>
</table>
</body>
</html>
<%
Call conn_close()
%>

